define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'keesuishoupai/report/index' + location.search,
                    del_url: 'keesuishoupai/report/del',
                    multi_url: 'keesuishoupai/report/multi',
                    table: 'keesuishoupai_report',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'content', title: __('Content')},
                        {field: 'level', title: __('Level'), operate: 'LIKE'},
                        {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'reviewadmin.nickname', title: __('Reviewadmin.nickname'), operate: 'LIKE'},
                        {field: 'solveadmin.nickname', title: __('Solveadmin.nickname'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'isopen', title: __('Isopen'),searchList: {"0":__('Isopen 0'),"1":__('Isopen 1')},formatter: Table.api.formatter.toggle},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1')},formatter: Table.api.formatter.status},
                        {field: 'buttons', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[{
                            name: 'detail',
                            text: __('查看'),
                            title: __('查看操作'),
                            classname: 'btn btn-xs btn-info btn-dialog',
                            url: 'keesuishoupai/report/show',
                            icon:"fa fa-eye",
                            callback: function (data) {
                                Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                            },
                            visible: function (row) {
                                    return true;
                            }
                        },{
                            name: 'examine',
                            text: __('审核'),
                            title: __('审核操作'),
                            classname: 'btn btn-xs btn-warning btn-dialog',
                            url: 'keesuishoupai/report/review',
                            callback: function (data) {
                                Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                            },
                            visible: function (row) {
                                if(!row.status){
                                    return true;
                                }
                                return false;
                            }
                        },{
                            name: 'solve',
                            text: __('处理'),
                            title: __('处理操作'),
                            classname: 'btn btn-xs btn-warning btn-dialog',
                            url: 'keesuishoupai/report/solve',
                            callback: function (data) {
                                Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                            },
                            visible: function (row) {
                                if(row.status === 1 && row.solvetime === 0){
                                    return true;
                                }
                                return false;
                            }
                        }], formatter: Table.api.formatter.operate},
                       
                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        review: function () {
            Controller.api.bindevent();
            $("input[name='row[level]']").change(function(e){
                $("input[name='row[score]']").val(e.currentTarget.dataset.score);
			});
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },
        show:function(){
            require.config({
                paths: {
                    'Tmap': ['https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77'],
                }
            });
            require(['Tmap'],function(){
                let lat = parseFloat(Config.row.lat);
                let lng = parseFloat(Config.row.lng);
                var center = new TMap.LatLng(lat, lng);
                //初始化地图
                var map = new TMap.Map("tmap-box", {
                    center: center,
                    zoom:17
                });
                var infoWindow = new TMap.InfoWindow({
                    map: map, 
                    position: center,
                    content: Config.row.address
                });
            });
            //图片预览
            $(".img-thumbnail").on("click",function(e){
                var value = Config.row.images;
                var arr = value != '' ? value.split(",") : [];
                var data = [];
                $.each(arr, function (index, value) {
                    data.push({
                        src: Fast.api.cdnurl(value),
                    });
                });
                Layer.photos({
                    photos: {
                        "start": $(this).parent().index(),
                        "data": data
                    },
                    anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            })
        },
        solve:function(){
            Controller.api.bindevent();
            require.config({
                paths: {
                    'Tmap': ['https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77'],
                }
            });
            require(['Tmap'],function(){
                let lat = parseFloat(Config.row.lat);
                let lng = parseFloat(Config.row.lng);
                var center = new TMap.LatLng(lat, lng);
                //初始化地图
                var map = new TMap.Map("tmap-box", {
                    center: center,
                    zoom:17
                });
                var infoWindow = new TMap.InfoWindow({
                    map: map, 
                    position: center,
                    content: Config.row.address
                });
            });
            //图片预览
            $(".img-thumbnail").on("click",function(e){
                var value = Config.row.images;
                var arr = value != '' ? value.split(",") : [];
                var data = [];
                $.each(arr, function (index, value) {
                    data.push({
                        src: Fast.api.cdnurl(value),
                    });
                });
                Layer.photos({
                    photos: {
                        "start": $(this).parent().index(),
                        "data": data
                    },
                    anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            })
        }
    };
    return Controller;
});